package dice.sinanya.tools.getinfo;

import dice.sinanya.entity.EntityTypeMessages;

import static dice.sinanya.system.MessagesTag.TAG_CLOCK;
import static dice.sinanya.tools.checkdata.CheckIsNumbers.isNumeric;
import static dice.sinanya.tools.makedata.Sender.sender;

public class Clock implements Runnable {
    EntityTypeMessages entityTypeMessages;

    public Clock(EntityTypeMessages entityTypeMessages) {
        this.entityTypeMessages = entityTypeMessages;
    }

    @Override
    public void run() {
        String tag = TAG_CLOCK;
        String msg = entityTypeMessages.getMsgGet().getMsg().trim().replaceFirst(tag.substring(0, tag.length() - 4), "").trim();
        if (isNumeric(msg)) {
            if (Integer.parseInt(msg) > 7200) {
                sender(entityTypeMessages, "定时器最高2小时，即7200秒");
                return;
            }
            sender(entityTypeMessages, "您的定时器:\t<" + msg + ">秒已开启计时");
            try {
                Thread.sleep(Integer.parseInt(msg) * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            sender(entityTypeMessages, "您的定时器:\t<" + msg + ">秒已到期");
        }
    }
}